package com.csot.ry.service.impl;

import java.util.List;

import cn.hutool.core.net.NetUtil;
import com.csot.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.csot.ry.mapper.TAssetIpMapper;
import com.csot.ry.domain.TAssetIp;
import com.csot.ry.service.ITAssetIpService;

/**
 * 资产ipService业务层处理
 *
 * @author csot
 * @date 2025-07-09
 */
@Service
public class TAssetIpServiceImpl implements ITAssetIpService {
    @Autowired
    private TAssetIpMapper tAssetIpMapper;

    /**
     * 查询资产ip
     *
     * @param id 资产ip主键
     * @return 资产ip
     */
    @Override
    public TAssetIp selectTAssetIpById(Long id) {
        return tAssetIpMapper.selectTAssetIpById(id);
    }

    /**
     * 查询资产ip列表
     *
     * @param tAssetIp 资产ip
     * @return 资产ip
     */
    @Override
    public List<TAssetIp> selectTAssetIpList(TAssetIp tAssetIp) {
        return tAssetIpMapper.selectTAssetIpList(tAssetIp);
    }

    /**
     * 新增资产ip
     *
     * @param tAssetIp 资产ip
     * @return 结果
     */
    @Override
    public int insertTAssetIp(TAssetIp tAssetIp) {
        tAssetIp.setCreateTime(DateUtils.getNowDate());
        return tAssetIpMapper.insertTAssetIp(tAssetIp);
    }

    /**
     * 修改资产ip
     *
     * @param tAssetIp 资产ip
     * @return 结果
     */
    @Override
    public int updateTAssetIp(TAssetIp tAssetIp) {
        tAssetIp.setUpdateTime(DateUtils.getNowDate());
        return tAssetIpMapper.updateTAssetIp(tAssetIp);
    }

    /**
     * 批量删除资产ip
     *
     * @param ids 需要删除的资产ip主键
     * @return 结果
     */
    @Override
    public int deleteTAssetIpByIds(Long[] ids) {
        return tAssetIpMapper.deleteTAssetIpByIds(ids);
    }

    /**
     * 删除资产ip信息
     *
     * @param id 资产ip主键
     * @return 结果
     */
    @Override
    public int deleteTAssetIpById(Long id) {
        return tAssetIpMapper.deleteTAssetIpById(id);
    }

    @Override
    public String importData(List<TAssetIp> assetIpList, boolean updateSupport) {
        for (TAssetIp assetIp : assetIpList) {
            assetIp.setIpI(NetUtil.ipv4ToLong(assetIp.getIp()));
            tAssetIpMapper.insertTAssetIp(assetIp);
        }
        return "导入成功";
    }
}
